//========================================================================
//  SE5 Empire Main - Terran - Captain Kwok's Balance Mod v125+
//========================================================================

#include Script_AI_GlobalConstants.txt
#include Script_AI_GlobalVariables.txt

//------------------------------------------------------------------------
// Global Constants
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// Global Variables
//------------------------------------------------------------------------

//------------------------------------------------------------------------
// Forward Declarations
//------------------------------------------------------------------------
deffunc

function Set_Race_Script_Values returns boolean
params
end

function Set_Race_Default_Settings returns boolean
params
end

function Set_Race_Vehicle_Amounts returns boolean
params
end

function Set_Race_Research_Spending returns boolean
params
end

function Set_Race_Research_Areas returns boolean
params
end

function Set_Race_Weapon_Choices returns boolean
params
  vehicle_type:              string
  vehicle_tonnage:           long
  design_type:               string
end

function Set_Race_Overall_Spending_Percentages returns boolean
params
end

function Set_Race_Strategy_Preferences returns boolean
params
end

function Set_Race_Political_Settings returns boolean
params
end

enddeffunc

//------------------------------------------------------------------------
// Includes
//------------------------------------------------------------------------

#include Script_AI_GlobalFunctions.txt
#include Script_AI_GlobalSettings.txt
#include Script_AI_Lists.txt
#include Script_AI_StateChange.txt
#include Script_AI_ColonyType.txt
#include Script_AI_Construction.txt
#include Script_AI_DesignCreation.txt
#include Script_AI_EnemyAnalysis.txt
#include Script_AI_PerformanceAnalysis.txt
#include Script_AI_Intelligence.txt
#include Script_AI_Orders_Planets.txt
#include Script_AI_Orders_Ships.txt
#include Script_AI_Restricted_SolarSystems.txt
#include Script_AI_Politics.txt
#include Script_AI_Research.txt

//------------------------------------------------------------------------
// Main
//------------------------------------------------------------------------
function Main returns boolean
begin

  // Base values for this AI
  call Set_Game_Settings()
  call Set_Race_Script_Values()

  // Set facility and vehicle IDs
  call Set_Facility_Id()
  call Set_Vehicle_Sizes()

  // Generate lists for AI use
  call AI_Generate_Lists()

  // Analyze enemies
  call AI_EnemyAnalysis()
  call AI_PerformanceAnalysis()

  // Compute any state changes
  call AI_StateChange()

  // Set race preferences
  call Set_Race_Default_Settings()
  call Set_Race_Point_Modifiers()
  call Set_Race_Resource_Modifiers()
  call Set_Race_Vehicle_Amounts()
  call Set_Race_Design_Types()
  call Set_Race_Research_Spending()
  call Set_Race_Research_Areas()
  call Set_Race_Overall_Spending_Percentages()
  call Set_Race_Strategy_Preferences()
  call Set_Race_Political_Settings()

  // Execute AI Controls
  call AI_SetColonyTypes()
  call AI_Restricted_SolarSystems()
  call AI_DesignCreation()
  call AI_Politics()
  call AI_Research()
  call AI_Intelligence()
  call AI_Orders_Planets()
  call AI_Orders_Ships()
  call AI_Construction()

end

//------------------------------------------------------------------------
// Main_Create_Specific_Design (Called externally in Create Design window)
//------------------------------------------------------------------------
function Main_Create_Specific_Design returns boolean
params
  design_id:                 long
  retval:                    boolean
begin

  call Set_Vehicle_Sizes()
  call Set_Race_Research_Areas()
  call Set_Race_Design_Types()
  set retval := Create_Specific_Design(design_id)

  return retval
end

//------------------------------------------------------------------------
// Set_Race_Script_Values
//------------------------------------------------------------------------
function Set_Race_Script_Values returns boolean
begin

  // Terran AI category
  set lng_AI_Categorization                                          := AI_CATEGORY_NEUTRAL
  set lng_AI_Secondary_Categorization                                := AI_CATEGORY_AGGRESSIVE
  set lng_AI_villain_Status                                          := AI_CATEGORY_NOT_VILLAIN

  // Consider a category change for the game (25% chance)
  if (sys_long_Game_Date = (Sys_Get_Game_Start_Date() + 1)) then
    if (Sys_Get_Random_Long(1, 4) = 1) then
      // Use our secondary category
      call Sys_Set_AI_Storage_Long(sys_long_Player_ID, 1, 12, lng_AI_Secondary_Categorization)
    else
      call Sys_Set_AI_Storage_Long(sys_long_Player_ID, 1, 12, 0)
    endif
    // Consider making the Terrans a game villain (Net 5% chance)
    if (Sys_Get_Random_Long(1, 5) = 1) then
      call Sys_Set_AI_Storage_Long(sys_long_Player_ID, 1, 13, AI_CATEGORY_VILLAIN)
    endif
  endif

  // Check to see if we're using our secondary category, if yes, then set our category to our secondary category
  if (Sys_Get_AI_Storage_Long(sys_long_Player_ID, 1, 12) > 0) then
    set lng_AI_Categorization := lng_AI_Secondary_Categorization
    // Debug text
    call Sys_Debug_Print("Enemy Analysis", "  - Using Secondary AI Category (" + Sys_Convert_Long_To_String(lng_AI_Secondary_Categorization) + ")")
  endif

  // Check to see if we're a game villain
  if (Sys_Get_AI_Storage_Long(sys_long_Player_ID, 1, 13) > 0) then
    set lng_AI_Villain_Status := AI_CATEGORY_VILLAIN
    // Debug text
    call Sys_Debug_Print("Enemy Analysis", "  - Are a Game Villain!")
  endif

  // Terran racial traits
  set bool_Race_Uses_Crystalline_Tech                                := FALSE
  set bool_Race_Uses_Interdimensional_Tech                           := FALSE
  set bool_Race_Uses_Organic_Tech                                    := FALSE
  set bool_Race_Uses_Psychic_Tech                                    := FALSE
  set bool_Race_Uses_Temporal_Tech                                   := FALSE
  set bool_Race_Uses_Religious_Tech                                  := FALSE

  // Terran starting strategies
  if (lng_AI_Categorization = AI_CATEGORY_NEUTRAL) then
    set lng_AI_Empire_Strategy                                         := AI_EMPIRE_STRATEGY_PEACEFUL
    set lng_AI_Empire_Design_Strategy                                  := AI_DESIGN_STRATEGY_MIXED
  else
    set lng_AI_Empire_Strategy                                         := AI_EMPIRE_STRATEGY_WEAK_ATTACK
    set lng_AI_Empire_Design_Strategy                                  := AI_DESIGN_STRATEGY_MIXED
  endif

end

//------------------------------------------------------------------------
// Set_Race_Default_Settings
//------------------------------------------------------------------------
function Set_Race_Default_Settings returns boolean
begin

  // Terran design type preferences
  set bool_Race_Uses_Mines                                           := TRUE
  set bool_Race_Uses_Remote_Mines                                    := TRUE
  set bool_Race_Uses_Fighters                                        := TRUE
  set bool_Race_Uses_Remote_Fighters                                 := TRUE
  set bool_Race_Uses_Satellites                                      := TRUE
  set bool_Race_Uses_Remote_Satellites                               := FALSE
  set bool_Race_Uses_Troops                                          := TRUE
  set bool_Race_Uses_Weapon_Platforms                                := TRUE
  set bool_Race_Uses_Drones                                          := TRUE
  set bool_Race_Uses_Remote_Drones                                   := TRUE
  set bool_Race_Uses_Explorer_Ships                                  := TRUE
  set bool_Race_Uses_Scout_Ships                                     := bool_Race_Is_Not_Alone
  set bool_Race_Uses_Patrol_Ships                                    := bool_Race_Is_Not_Alone
  set bool_Race_Uses_Seeker_Ships                                    := TRUE
  set bool_Race_Uses_Kamikaze_Ships                                  := FALSE
  set bool_Race_Uses_Boarding_Ships                                  := TRUE
  set bool_Race_Uses_Bombardment_Ships                               := TRUE
  set bool_Race_Uses_Plague_Ships                                    := FALSE
  set bool_Race_Uses_Remote_Mining_Ships                             := TRUE
  set bool_Race_Uses_Remote_Farming_Ships                            := TRUE
  set bool_Race_Uses_Remote_Refining_Ships                           := TRUE
  set bool_Race_Uses_Stellar_Manipulation_Ships                      := TRUE
  set bool_Race_Uses_Evil_Stellar_Manipulation_Ships                 := TRUE

  // Terran component preferences
  set bool_Race_Uses_Normal_Armor                                    := TRUE
  set bool_Race_Uses_Normal_Shields                                  := TRUE
  set bool_Race_Uses_Cloaking_Devices                                := TRUE
  set bool_Race_Uses_Master_Computers                                := TRUE
  // Ratio of launchers on carriers (30 to 80)
  set lng_AI_Design_Ratio_Launchers                                  := 56

  // Terran unit percentages for colonies
  set lng_AI_Pct_Troops_For_Colonies                                 := 80
  set lng_AI_Pct_Fighters_For_Colonies                               := 40
  set lng_AI_Pct_Satellites_For_Colonies                             := 100
  set lng_AI_Pct_Mines_For_Colonies                                  := 20
  set lng_AI_Pct_Drones_For_Colonies                                 := 40

  // Terran unit group sizes
  set lng_AI_Min_Fighter_Group_Size                                  := 20
  set lng_AI_Min_Satellite_Group_Size                                := 5
  set lng_AI_Min_Drone_Group_Size                                    := 5
  set lng_AI_Min_Mine_Group_Size                                     := 20

  // Terran scrap values
  set lng_Ship_Obsolete_Time_To_Scrap                                := 75
  set lng_Max_Ships_To_Scrap                                         := 5
  set lng_Unit_Obsolete_Time_To_Scrap                                := 100
  set lng_Max_Units_To_Scrap                                         := 150

  // Terran attack/defense values
  set lng_Max_Attack_Systems                                         := 3
  set lng_Max_Defense_Systems                                        := 3

  // Terran fleet preferences
  set lng_Percent_Of_Attack_Ships_To_Use_For_Fleets                  := 90
  set lng_Pct_Fleets_For_Attack                                      := 50
  set lng_Pct_Fleets_For_Defense                                     := 50
  set lng_Pct_Ships_For_Attack_Fleets                                := 60
  set lng_Pct_Ships_For_Defense_Fleets                               := 40
  set lng_AI_Fleet_Size                                              := FLEET_SIZE_MEDIUM

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Vehicle_Amounts
//------------------------------------------------------------------------
function Set_Race_Vehicle_Amounts returns boolean
params
vars
  size_dist_mod:             long
  size_mod:                  long
  empire_mod:                long
  attack_mod:                long
  defense_mod:               long
  seeker_mod:                long
  baseship_mod:              long
  explore_mod:               long
  scout_mod:                 long
  patrol_mod:                long
  pd_mod:                    long
  kamikaze_mod:              long
  carrier_mod:               long
  base_mod:                  long
  troop_mod:                 long
  fighter_mod:               long
  wp_mod:                    long
  sat_mod:                   long
  mine_mod:                  long
  drone_mod:                 long
  minerals_mod:              long
  organics_mod:              long
  radioactives_mod:          long
begin

  // Terran ship size distribution modifiers
  if Is_Vehicle_Size_Available("Light Cruiser") then
    if (bool_AI_Design_Preference_Small) then
      set size_dist_mod := size_dist_mod + 10
      set size_mod := size_mod + 10
    endif
    if (bool_Enemy_Ships_Are_Much_Faster) then
      set size_dist_mod := size_dist_mod + 10
      set size_mod := size_mod + 10
    endif
    // Terran ship size distribution
    set lng_Pct_Small_Ships := 30 + Sys_Divide_Long(size_dist_mod, 2)
    set lng_Pct_Medium_Ships := 40 + Sys_Divide_Long(size_dist_mod, 2)
    set lng_Pct_Large_Ships := 30 - size_dist_mod
  else
    if Is_Vehicle_Size_Available("Destroyer") then
      set lng_Pct_Small_Ships := 40
      set lng_Pct_Medium_Ships := 60
    else
      set lng_Pct_Small_Ships := 100
    endif
  endif

  // Carriers
  if Is_Vehicle_Size_Available("Heavy Carrier") then
    set lng_Pct_Small_Carriers := 0
    set lng_Pct_Medium_Carriers := 50
    set lng_Pct_Large_Carriers := 50
  else
    if Is_Vehicle_Size_Available("Carrier") then
      set lng_Pct_Small_Carriers := 50
      set lng_Pct_Medium_Carriers := 50
    else
      set lng_Pct_Small_Carriers := 100
    endif
  endif

  // Bases
  if Is_Vehicle_Size_Available("Starbase") then
    set lng_Pct_Small_Bases := 50
    set lng_Pct_Large_Bases := 50
  else
    set lng_Pct_Small_Bases := 100
  endif

  // Weapon Platforms
  if Is_Vehicle_Size_Available("Large Weapon Platform") then
    set lng_Pct_Small_WPs := 67
    set lng_Pct_Large_WPs := 33
  else
    set lng_Pct_Small_WPs := 100
  endif

  // Terran vehicle amount modifiers
  // Empire size
  set empire_mod := Sys_Divide_Long(lng_AI_Empire_Num_Facilities, 1500)

  // Diplomacy
  if (bool_Race_Is_Not_Alone) then
    set explore_mod := explore_mod - 10
    set scout_mod := scout_mod + 10
  else
    set explore_mod := explore_mod + 10
  endif

  if (lng_AI_Num_Of_Enemies > 0) then
    set patrol_mod := patrol_mod + 10
  endif

  // Combat performance
  if (bool_Race_Losing_Colonies_In_Combat) then
    set wp_mod := wp_mod + 50
  endif

  if (bool_Race_Ground_Combat_Poor) then
    set troop_mod := troop_mod + 1000
  endif

 // Technology
  if Is_Vehicle_Size_Available("Baseship") then
    set baseship_mod := baseship_mod + 10
  endif

  // Enemy designs
  if (bool_Enemy_Uses_Seeker_Weapons) or (bool_Enemy_Uses_Long_Range_Seeker_Weapons) then
    set pd_mod := pd_mod + 5
    set fighter_mod := fighter_mod + 500
  endif

  if (bool_Enemy_Uses_Direct_Fire_Weapons) then
    set attack_mod := attack_mod + 10
    set defense_mod := defense_mod + 5
    set seeker_mod := seeker_mod - 15
  endif

  if (bool_Enemy_Ships_Are_Faster) then
    set attack_mod := attack_mod - 15
    set defense_mod := defense_mod - 10
    set seeker_mod := seeker_mod + 20
    set fighter_mod := fighter_mod + 500
    set drone_mod := drone_mod + 50
  endif

  if (bool_Enemy_Ships_Are_Much_Faster) then
    set attack_mod := attack_mod - 10
    set defense_mod := defense_mod - 10
    set seeker_mod := seeker_mod + 10
    set fighter_mod := fighter_mod + 500
    set drone_mod := drone_mod + 50
  endif

  // Resource availability
  if (bool_Race_Minerals_Prod_Low) or (bool_Race_Maintenance_High) then
    set minerals_mod := minerals_mod + 10
  endif
  if (bool_Race_Organics_Prod_Low) or (bool_Race_Maintenance_High) then
    set organics_mod := organics_mod + 2
  endif
  if (bool_Race_Radioactives_Prod_Low) or (bool_Race_Maintenance_High) then
    set radioactives_mod := radioactives_mod + 6
  endif

  // Empire strategy
  if (bool_AI_Strategy_Peaceful) then
    // No changes
  endif

  if (bool_AI_Strategy_Defend) then
    set attack_mod := attack_mod - 10
    set seeker_mod := seeker_mod + 10
    set patrol_mod := patrol_mod + 5
    set pd_mod := pd_mod + 5
    set wp_mod := wp_mod + 50
    set mine_mod := mine_mod + 1000
  endif

  if (bool_AI_Strategy_Buildup) then
    set attack_mod := attack_mod + 10
    set defense_mod := defense_mod - 5
    set seeker_mod := seeker_mod + 10
    set pd_mod := pd_mod + 5
    set fighter_mod := fighter_mod + 500
  endif

  if (bool_AI_Strategy_Attack) then
    set attack_mod := attack_mod + 10
    set defense_mod := defense_mod - 5
    set seeker_mod := seeker_mod + 10
    set pd_mod := pd_mod + 5
    set fighter_mod := fighter_mod + 500
  endif

  if (bool_AI_Strategy_Last_Stand) or (bool_AI_Strategy_Flame_Out) then
    set attack_mod := attack_mod - 25
    set seeker_mod := seeker_mod - 25
    set explore_mod := -10
    set empire_mod := -5
    set fighter_mod := fighter_mod + 500
    set wp_mod := wp_mod + 100
    set sat_mod := sat_mod + 100
    set mine_mod := mine_mod + 1000
  endif

  // Design strategy
  if (bool_AI_Design_Preference_Direct_Fire) then
    set attack_mod := attack_mod + 25
    set seeker_mod := seeker_mod - 25
  endif

  if (bool_AI_Design_Preference_Seeker) then
    set attack_mod := attack_mod - 25
    set seeker_mod := seeker_mod + 25
  endif

  // Terran wanted vehicles per 1000 facilities
  // Ships
  set lng_Num_Attack_Ships             := 50 + attack_mod + Sys_Divide_Long(size_mod, 2)
  set lng_Num_Defense_Ships            := 25 + defense_mod
  set lng_Num_Seeker_Ships             := 50 + seeker_mod + Sys_Divide_Long(size_mod, 2)
  set lng_Num_PD_Ships                 := 10 + pd_mod
  set lng_Num_Explorer_Ships           := 10 + explore_mod
  set lng_Num_Scout_Ships              := 0 + scout_mod
  set lng_Num_Patrol_Ships             := 5 + patrol_mod
  set lng_Num_Boarding_Ships           := 0
  set lng_Num_Bombardment_Ships        := 4
  set lng_Num_Kamikaze_Ships           := 0
  set lng_Num_Carriers                 := 10 + carrier_mod
  set lng_Num_Drone_Carriers           := 4
  set lng_Num_Base_Ships               := 0 + baseship_mod
  set lng_Num_Space_Yard_Ships         := 4 - empire_mod
  set lng_Num_Repair_Ships             := 6 - empire_mod
  set lng_Num_Supply_Transports        := 6 - empire_mod
  set lng_Num_Troop_Transports         := 6 - empire_mod
  set lng_Num_Cargo_Transports         := 6 - empire_mod
  set lng_Num_Pop_Transports           := 6 - empire_mod
  set lng_Num_Plague_Ships             := 0
  set lng_Num_Sat_Layers               := 0
  set lng_Num_Mine_Layers              := 6 - empire_mod
  set lng_Num_Mine_Sweepers            := 12
  set lng_Num_Mining_Ships             := 18 + minerals_mod
  set lng_Num_Farming_Ships            := 3 + organics_mod
  set lng_Num_Refining_Ships           := 6 + radioactives_mod

  // Bases
  set lng_Num_Base_Space_Yards         := 10 - empire_mod
  set lng_Num_Defense_Bases            := 15 + base_mod

  // Troops
  If Is_Vehicle_Size_Available("Large Troop") then
    set lng_Num_Troops                 := 500 + Sys_Divide_Long(troop_mod, 4)
    set lng_Num_Light_Troops           := 1500 + Sys_Divide_Long(troop_mod, 2)
    set lng_Num_Heavy_Troops           := 500 + Sys_Divide_Long(troop_mod, 4)
  else
    If Is_Vehicle_Size_Available("Medium Troop") then
      set lng_Num_Troops               := 1000 + Sys_Divide_Long(troop_mod, 2)
      set lng_Num_Light_Troops         := 2000 + Sys_Divide_Long(troop_mod, 2)
    else
      set lng_Num_Troops               := 2500 + troop_mod
    endif
  endif

  // Fighters
  set lng_Num_Fighters                 := 1500 + Sys_Divide_Long(fighter_mod, 2)
  set lng_Num_Fighter_Bombers          := 1500 + Sys_Divide_Long(fighter_mod, 2)
  set lng_Num_Kamikaze_Fighters        := 0

  // Weapon Platforms
  set lng_Num_Weapon_Platforms         := 150 + Sys_Divide_Long(wp_mod, 2)
  set lng_Num_Seeker_WPs               := 250 + Sys_Divide_Long(wp_mod, 2)

  // Satellites
  set lng_Num_Satellites               := 100 + Sys_Divide_Long(sat_mod, 2)
  set lng_Num_PD_Sats                  := 25 + Sys_Multiply_Long(pd_mod, 2)
  set lng_Num_Seeker_Sats              := 100 + Sys_Divide_Long(sat_mod, 2)
  set lng_Num_Recon_Sats               := 20
  set lng_Num_Repair_Sats              := 25

  // Mines
  set lng_Num_Mines                    := 4000 + mine_mod

  // Drones
  set lng_Num_Atk_Drones               := 200 + Sys_Divide_Long(drone_mod, 2)
  set lng_Num_Def_Drones               := 50 + Sys_Divide_Long(drone_mod, 4) - seeker_mod
  set lng_Num_Seeker_Drones            := 200 + Sys_Divide_Long(drone_mod, 2) + seeker_mod
  set lng_Num_Kamikaze_Drones          := 0
  set lng_Num_Bombardment_Drones       := 0
  set lng_Num_Repair_Drones            := 0

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Research_Spending
//------------------------------------------------------------------------
function Set_Race_Research_Spending returns boolean
vars
  research_pts:              long
  research_mod:              long
begin

  // Get our current research points
  set research_pts := Sys_Get_Empire_Current_Points(sys_long_Player_ID, POINT_TYPE_RESEARCH)

  // Set our base research and intel point percentages (Should add to 100)
  set lng_Pct_Pts_Research := 80
  set lng_Pct_Pts_Intel := 20

  // Set research modifier
  set research_mod := Sys_Min_Long(Sys_Divide_Long(research_pts, 10000), 15)

  // Set our research spending groups
  call lst_Research_Spending_Group_Name.add("Cultural Advancement")
  call lst_Research_Spending_Group_Name.add("Theoretical Science")
  call lst_Research_Spending_Group_Name.add("Applied Science")
  call lst_Research_Spending_Group_Name.add("Weapon Technology")

  // Set our research group spending
  case (Sys_Get_AI_State(sys_long_Player_ID))
    AI_STATE_EXPLORE_AND_EXPAND:
      call lst_Research_Spending_For_Group.add(1)
      call lst_Research_Spending_For_Group.add(40 + research_mod)
      call lst_Research_Spending_For_Group.add(39)
      call lst_Research_Spending_For_Group.add(20 - research_mod)
    AI_STATE_INFRASTRUCTURE:
      call lst_Research_Spending_For_Group.add(5)
      call lst_Research_Spending_For_Group.add(25 - research_mod)
      call lst_Research_Spending_For_Group.add(45 + (research_mod * 2))
      call lst_Research_Spending_For_Group.add(25 - research_mod)
    AI_STATE_ATTACK:
      call lst_Research_Spending_For_Group.add(1)
      call lst_Research_Spending_For_Group.add(19 - research_mod)
      call lst_Research_Spending_For_Group.add(45 + (research_mod * 2))
      call lst_Research_Spending_For_Group.add(35 - research_mod)
    AI_STATE_DEFEND:
      call lst_Research_Spending_For_Group.add(1)
      call lst_Research_Spending_For_Group.add(19 - research_mod)
      call lst_Research_Spending_For_Group.add(50 + (research_mod * 2))
      call lst_Research_Spending_For_Group.add(30 - research_mod)
    AI_STATE_NOT_CONNECTED:
      if Is_Tech_Area_Visible("Stellar Manipulation") then
        call lst_Research_Spending_For_Group.add(1)
        call lst_Research_Spending_For_Group.add(10)
        call lst_Research_Spending_For_Group.add(80)
        call lst_Research_Spending_For_Group.add(9)
      else
        call lst_Research_Spending_For_Group.add(1)
        call lst_Research_Spending_For_Group.add(70)
        call lst_Research_Spending_For_Group.add(20)
        call lst_Research_Spending_For_Group.add(9)
      endif
  endcase

  // Set research priority level based on number of wars we are in
  set lng_Research_Priority_Level := RESEARCH_PRIORITY_LOW

  if (lng_AI_Num_Of_Wars = 2) then
    set lng_Research_Priority_Level := RESEARCH_PRIORITY_MEDIUM
  endif
  if (lng_AI_Num_Of_Wars = 3) then
    set lng_Research_Priority_Level := RESEARCH_PRIORITY_HIGH
  endif
  if (lng_AI_Num_Of_Wars >= 4) then
    set lng_Research_Priority_Level := RESEARCH_PRIORITY_CRITICAL
  endif

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Research_Areas
//------------------------------------------------------------------------
function Set_Race_Research_Areas returns boolean
begin

  // Terran weapons to research
  if Is_Tech_Area_Visible("Weapon Mounts") then
    call Add_Tech_Area_To_Research_List("Weapon Mounts", 1, Is_Tech_Area_Available("Small Ship Construction", 6))
  endif

  if Is_Tech_Area_Visible("Energy Stream Weapons") then
    // Anti-Proton Beam
    call Add_Tech_Area_To_Research_List("Energy Stream Weapons", 11, TRUE)
  else
    // Depleted Uranium Cannon
    call Add_Tech_Area_To_Research_List("Projectile Weapons", 11, TRUE)
    // X-Ray Laser
    call Add_Tech_Area_To_Research_List("Focused-Energy Weapons", 11, TRUE)
  endif
  // Ripper Beam, Incinerator Beam, Wave-Motion Gun
  if Is_Tech_Area_Visible("High-Energy Discharge Weapons") then
    call Add_Tech_Area_To_Research_List("High-Energy Discharge Weapons", 15, bool_Enemy_Ships_Are_Slower or bool_AI_Design_Preference_Direct_Fire)
  endif

  if Is_Tech_Area_Visible("Torpedo Weapons") then
    // Anti-Matter Torpedo, Quantum Torpedo, Gamma Pulse Torpedo
    call Add_Tech_Area_To_Research_List("Torpedo Weapons", 20, bool_Enemy_Uses_Mostly_Shields)
    // Anti-Matter Torpedo, Quantum Torpedo
    call Add_Tech_Area_To_Research_List("Torpedo Weapons", 16, TRUE)
  else
    // Capital Ship Missile
    call Add_Tech_Area_To_Research_List("Missile Weapons", 11, TRUE)
  endif

  if Is_Tech_Area_Visible("Weapon Overloading Weapons") then
    // Weapon Disrupter, Tachyon Projection Cannon
    call Add_Tech_Area_To_Research_List("Weapon Overloading Weapons", 11, TRUE)
  endif

  if Is_Tech_Area_Visible("Shield Damaging Weapons") then
    // Shield Depleter, Shield Disrupter
    call Add_Tech_Area_To_Research_List("Shield Damaging Weapons", 11, bool_Enemy_Uses_Mostly_Shields)
  endif

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Weapon_Choices
//------------------------------------------------------------------------
function Set_Race_Weapon_Choices returns boolean
params
  vehicle_type:              string
  vehicle_tonnage:           long
  design_type:               string
begin

  // Clear previous lists
  call lst_Primary_Weapon_Name.clear()
  call lst_Secondary_Weapon_Name.clear()
  call lst_Heavy_Weapon_Name.clear()
  call lst_Special_Weapon_Name.clear()
  call lst_Bombardment_Weapon_Name.clear()
  call lst_Primary_PD_Weapon_Name.clear()
  call lst_Secondary_PD_Weapon_Name.clear()
  call lst_Special_PD_Weapon_Name.clear()
  call lst_Primary_Armor_Name.clear()
  call lst_Secondary_Armor_Name.clear()

  // Terran Ship weapon choices
  // Ship (Attack) = Primary + Heavy (>=400kT) + Special (>=750kT)
  // Ship (Defense) = Secondary + Heavy (>=400kT) + Special (>=750kT)
  // Ship (Seeker) = Primary (>=450kT) + Heavy
  if (vehicle_type = "Ship") then
    // Primary
    call Add_Weapon_To_List("Ripper Beam", "Primary", bool_Enemy_Ships_Are_Slower and vehicle_tonnage < 450)
    call Add_Weapon_To_List("Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Incinerator Beam", "Secondary", vehicle_tonnage > 600)
    call Add_Weapon_To_List("Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Gamma Pulse Torpedo", "Heavy", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Heavy", TRUE)
    // Special
    call Add_Weapon_To_List("Shield Depleter", "Special", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Weapon Disrupter", "Special", TRUE)
    call Add_Weapon_To_List("Tachyon Projection Cannon", "Special", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Special", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Special", TRUE)
    // Bombardment
    call Add_Weapon_To_List("Smart Bomb (Cargo)", "Bombardment", TRUE)
    call Add_Weapon_To_List("Planetary Napalm", "Bombardment", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Bombardment", TRUE)
  endif

  // Terran Base weapon choices
  // Primary + Secondary (1/500kT) + Heavy + Special (1/1000kT)
  if (vehicle_type = "Base") then
    // Primary
    call Add_Weapon_To_List("Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Wave-Motion Gun", "Secondary", TRUE)
    call Add_Weapon_To_List("Incinerator Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Ripper Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Gamma Pulse Torpedo", "Heavy", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Heavy", TRUE)
    // Special
    call Add_Weapon_To_List("Shield Depleter", "Special", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Weapon Disrupter", "Special", TRUE)
    call Add_Weapon_To_List("Tachyon Projection Cannon", "Special", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Special", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Special", TRUE)
  endif

  // Terran Troop weapon choices
  // Troop (Light) = Primary
  // Troop = Primary + Secondary (>=18kT)
  // Troop (Heavy) = Heavy
  if (vehicle_type = "Troop") then
    // Primary
    call Add_Weapon_To_List("Ground Cannon", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Small Ripper Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Small Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Small Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Rocket Pods", "Heavy", TRUE)
    call Add_Weapon_To_List("Small Nuclear Missile", "Heavy", TRUE)
  endif

  // Terran Fighter weapon choices
  // Fighter = Primary + Secondary (>=20kT)
  // Fighter (Bomber) = Heavy
  if (vehicle_type = "Fighter") then
    // Primary
    call Add_Weapon_To_List("Small Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("Small X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Small Incinerator Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Small Ripper Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Small Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Small Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Small Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Small Nuclear Missile", "Heavy", TRUE)
  endif

  // Terran Satellite weapon choices
  // Satellite = Primary + Secondary (>=100kT)
  // Satellite (Seeker) = Heavy
  if (vehicle_type = "Satellite") then
    // Primary
    call Add_Weapon_To_List("Ripper Beam", "Primary", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Gamma Pulse Torpedo", "Heavy", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Heavy", TRUE)
  endif

  // Terran Weapon Platform weapon choices
  // Weapon Platform = Primary + Secondary (1/250kT) + Heavy + Special (1/250kT)
  // Weapon Platform (Seeker) = Heavy
  if (vehicle_type = "Weapon Platform") then
    // Primary
    call Add_Weapon_To_List("Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Wave-Motion Gun", "Secondary", TRUE)
    call Add_Weapon_To_List("Incinerator Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Ripper Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Gamma Pulse Torpedo", "Heavy", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Heavy", TRUE)
    // Special
    call Add_Weapon_To_List("Shield Depleter", "Special", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Weapon Disrupter", "Special", TRUE)
    call Add_Weapon_To_List("Tachyon Projection Cannon", "Special", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Special", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Special", TRUE)
  endif

  // Terran Drone weapon choices
  // Drone (Attack) = Primary + Secondary
  // Drone (Defense) = Heavy
  // Drone (Bombardment) = Bombardment
  if (vehicle_type = "Drone") then
    // Primary
    call Add_Weapon_To_List("Ripper Beam", "Primary", TRUE)
    call Add_Weapon_To_List("Anti-Proton Beam", "Primary", TRUE)
    call Add_Weapon_To_List("X-Ray Laser", "Primary", TRUE)
    // Secondary
    call Add_Weapon_To_List("Anti-Proton Beam", "Secondary", TRUE)
    call Add_Weapon_To_List("Depleted Uranium Cannon", "Secondary", TRUE)
    // Heavy
    call Add_Weapon_To_List("Gamma Pulse Torpedo", "Heavy", bool_Enemy_Uses_Mostly_Shields)
    call Add_Weapon_To_List("Quantum Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Anti-Matter Torpedo", "Heavy", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Heavy", TRUE)
    // Bombardment
    call Add_Weapon_To_List("Smart Bomb (Cargo)", "Bombardment", TRUE)
    call Add_Weapon_To_List("Planetary Napalm", "Bombardment", TRUE)
    call Add_Weapon_To_List("Capital Ship Missile", "Bombardment", TRUE)
  endif

  // Terran Point-Defense Choices
  // Primary Point-Defense Weapon
  call Add_Weapon_To_List("Bomblet Missile", "Primary PD", design_type = "Ship (Seeker)" and vehicle_tonnage < 600)
  call Add_Weapon_To_List("Bomblet Missile", "Primary PD", bool_Enemy_Uses_Seeker_Weapons and design_type = "Ship (Point-Defense)")
  call Add_Weapon_To_List("Point-Defense Beam", "Primary PD", TRUE)
  call Add_Weapon_To_List("Point-Defense Cannons", "Primary PD", TRUE)
  // Secondary Point-Defense Weapon
  call Add_Weapon_To_List("Point-Defense Beam", "Secondary PD", design_type = "Ship (Defense)" or design_type = "Ship (Point-Defense)")
  call Add_Weapon_To_List("Bomblet Missile", "Secondary PD", bool_Enemy_Uses_Seeker_Weapons)
  call Add_Weapon_To_List("Flak Cannon", "Secondary PD", bool_Enemy_Uses_Seeker_Weapons)
  call Add_Weapon_To_List("Point-Defense Cannons", "Secondary PD", TRUE)
  // Special Point-Defense Weapon
  call Add_Weapon_To_List("Flak Cannon", "Special PD", bool_Enemy_Uses_Seeker_Weapons)
  call Add_Weapon_To_List("Anti-Fighter Rocket", "Special PD", design_type = "Ship (Point-Defense)")
  call Add_Weapon_To_List("Point-Defense Cannons", "Special PD", TRUE)

  // Terran Armor choices
  if (vehicle_type = "Troop") or (vehicle_type = "Fighter") then
    call lst_Primary_Armor_Name.add("Small Armor")
    call lst_Secondary_Armor_Name.add("Small Emissive Armor")
  else
    call lst_Primary_Armor_Name.add("Heavy Armor")
    call lst_Secondary_Armor_Name.add("Emissive Armor")
  endif

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Overall_Spending_Percentages
//------------------------------------------------------------------------
function Set_Race_Overall_Spending_Percentages returns boolean
vars
  ai_state:                  long
begin

  // Get our current state
  set ai_state := Sys_Get_AI_State(sys_long_Player_ID)

  // Set our construction focus
  case ai_state
    AI_STATE_EXPLORE_AND_EXPAND:
      set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_MEDIUM
    AI_STATE_INFRASTRUCTURE:
      set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_MEDIUM
    AI_STATE_ATTACK:
      set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_HIGH
    AI_STATE_DEFEND:
      set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_MEDIUM
    AI_STATE_NOT_CONNECTED:
      set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_LOW
  endcase

  if (bool_Race_Maintenance_High) or (bool_Race_Minerals_Low) or (bool_Race_Organics_Low) or (bool_Race_Radioactives_Low) then
    set lng_Vehicle_Construction_Priority_Level := VEHICLE_PRIORITY_LOW
  endif

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Strategy_Preferences
//------------------------------------------------------------------------
function Set_Race_Strategy_Preferences returns boolean
vars
begin

  // Terran ship strategies
  set lng_Atk_Ship_Atk_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Short Range")
  set lng_Atk_Ship_Def_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Short Range")
  set lng_Def_Ship_Atk_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Optimal Range")
  set lng_Def_Ship_Def_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Optimal Range")
  set lng_Skr_Ship_Atk_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Maximum Range")
  set lng_Skr_Ship_Def_Strat := Sys_Get_Strategy_With_Name(sys_long_Player_ID, "Maximum Range")

  // Terran fleet formations
  if (lng_AI_Empire_Design_Strategy = AI_DESIGN_STRATEGY_DIRECTFIRE or lng_AI_Empire_Design_Strategy = AI_DESIGN_STRATEGY_DIRECTFIRE_SMALL) then
    set lng_TF_Fill_Strategy := AI_TASK_FORCE_FILL_SPREAD_THREE
    set lng_Atk_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Crossbow (S)")
    set lng_Atk_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("Wall (S)")
    set lng_Def_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Crossbow (S)")
    set lng_Def_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("Wall (S)")
  else
    // Mix of direct fire and seeker ships
    if (lng_AI_Empire_Design_Strategy = AI_DESIGN_STRATEGY_MIXED or lng_AI_Empire_Design_Strategy = AI_DESIGN_STRATEGY_MIXED_SMALL) then
      set lng_TF_Fill_Strategy := AI_TASK_FORCE_FILL_SPREAD_TWO
      set lng_Atk_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Shell (S)")
      set lng_Atk_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("X (S)")
      set lng_Def_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Shell (S)")
      set lng_Def_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("X (S)")
    else
      // Mostly seeker ships
      set lng_TF_Fill_Strategy := AI_TASK_FORCE_FILL_BY_TYPE
      set lng_Atk_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Swarm (S)")
      set lng_Atk_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("Crossbow (S)")
      set lng_Def_Fleet_Atk_Form := Sys_Get_Fleet_Formation_With_Name("Swarm (S)")
      set lng_Def_Fleet_Def_Form := Sys_Get_Fleet_Formation_With_Name("Crossbow (S)")
    endif
  endif

  // Terran task force formations
  set lng_TF_Atk_Ship_Atk_Form := Sys_Get_Task_Force_Formation_With_Name("Hammer (S)")
  set lng_TF_Atk_Ship_Def_Form := Sys_Get_Task_Force_Formation_With_Name("Brick (S)")
  set lng_TF_Def_Ship_Atk_Form := Sys_Get_Task_Force_Formation_With_Name("Hammer (S)")
  set lng_TF_Def_Ship_Def_Form := Sys_Get_Task_Force_Formation_With_Name("Brick (S)")
  set lng_TF_Skr_Ship_Atk_Form := Sys_Get_Task_Force_Formation_With_Name("Column (S)")
  set lng_TF_Skr_Ship_Def_Form := Sys_Get_Task_Force_Formation_With_Name("Zipper (S)")

  return TRUE
end

//------------------------------------------------------------------------
// Set_Race_Political_Settings
//------------------------------------------------------------------------
function Set_Race_Political_Settings returns boolean
begin

  // Terran speech file
  set str_Politics_Speech_Datafile_Filename                          := "Terran_AI_Speech.txt"

  // Terran diplomacy values
  set lng_Political_Message_Score_Percent_For_Demanding_Tone         := 80
  set lng_Political_Message_Score_Percent_For_Pleading_Tone          := 125
  set lng_Politics_Base_Anger_Level                                  := 50
  set lng_Politics_Min_Anger_Allowed                                 := 10
  set lng_Politics_Anger_Reduction_For_Wars                          := 5
  set lng_Politics_Anger_Reduction_For_Similarity                    := 5
  set lng_Politics_Max_Anger_To_Propose_Treaty                       := 60
  set lng_Politics_Max_Anger_To_Accept_Treaty                        := 70
  set lng_Politics_Max_Anger_To_Counter_Treaty                       := 75
  set lng_Politics_Max_Anger_To_Accept_Gift                          := 100
  set lng_Politics_Max_Anger_To_Trade                                := 80
  set lng_Politics_Min_Anger_To_Declare_War                          := 85
  set lng_Politics_Min_Time_To_Declare_War                           := 15
  set lng_Politics_Min_Anger_To_Break_Treaty                         := 70
  set lng_Politics_Min_Time_To_Break_Treaty                          := 10
  set lng_Politics_Trade_Value_Percent_For_Enemy                     := 150
  set lng_Politics_Trade_Value_Percent_For_Friend                    := 100
  set lng_Politics_Min_Fear_To_Make_Peace                            := 20
  set lng_Politics_Min_Fear_To_Surrender                             := 55
  set lng_Politics_Min_Fear_To_Give_Enemy_Gift                       := 20
  set lng_Politics_Min_Fear_To_Give_Friend_Gift                      := 10
  set lng_Politics_Min_Fear_To_Accept_Enemy_Demand                   := 25
  set lng_Politics_Min_Fear_To_Accept_Friend_Demand                  := 10
  set lng_Politics_Max_Concurrent_Requests_To_Honor_From_One_Player  := 2
  set lng_Politics_Max_Time_To_Honor_A_Request                       := 10
  set lng_Politics_Percent_Chance_To_Propose_Treaty                  := 20
  set lng_Politics_Percent_Chance_To_Change_Treaty                   := 5

  set lng_Politics_Friendship_Pts_Ok_Friend                          := 5
  set lng_Politics_Friendship_Pts_Good_Friend                        := 10

  // Terran alliance diplomacy values
  set lng_Politics_Max_Anger_To_Propose_Alliance                     := 40
  set lng_Politics_Max_Anger_To_Accept_Alliance                      := 50
  set lng_Politics_Max_Anger_To_Counter_Alliance                     := 50
  set lng_Politics_Alliance_Max_Anger_To_Add_Member                  := 60
  set lng_Politics_Alliance_Min_Anger_To_Remove_Member               := 75
  set lng_Politics_Alliance_Max_Anger_To_Accept_Rule_Change          := 50
  set lng_Politics_Alliance_Max_Anger_To_Accept_Send_Message         := 60
  set lng_Politics_Alliance_Max_Anger_To_Accept_Reply_Message        := 70

  // Terran anger amounts for political status
  set lng_Politics_Max_Friendship_Pts_For_Anger                      := 10
  set lng_Politics_Anger_Amount_For_Known_Status_Time                := 1
  set lng_Politics_Anger_Amount_For_Treaty_Status_Time               := -2
  set lng_Politics_Anger_Amount_For_War_Status_Time                  := 4
  set lng_Politics_Anger_Amount_Friend_Of_Friend                     := -2
  set lng_Politics_Anger_Amount_Friend_Of_Enemy                      := 3
  set lng_Politics_Anger_Amount_Enemy_Of_Enemy                       := -2
  set lng_Politics_Anger_Amount_Enemy_Of_Friend                      := 3
  set lng_Politics_Min_Anger_For_Political_Status                    := -20
  set lng_Politics_Max_Anger_For_Political_Status                    := 20
  set lng_Politics_Min_Anger_For_Political_Status_With_Others        := -10
  set lng_Politics_Max_Anger_For_Political_Status_With_Others        := 10
  set lng_Politics_Min_Anger_Flux                                    := -3
  set lng_Politics_Max_Anger_Flux                                    := 3

  set lng_Politics_Anger_Reduction_For_Wars                          := -10
  set lng_Politics_Anger_Reduction_For_Similarity                    := -7
  set lng_Politics_Anger_Increase_For_Dissimilarity                  := 5
  set lng_Politics_Anger_Increase_For_Mega_Evil                      := 15
  set lng_Politics_Anger_Reduction_For_Mega_Evil                     := -15
  set lng_Politics_Anger_Reduction_For_AI_Team                       := -10
  set lng_Politics_Anger_Reduction_For_Common_Enemy                  := -15
  set lng_Politics_Anger_Increase_For_Friendly_Galaxy                := 15

  // Terran anger amounts for events
  // Combat
  set lng_AI_Anger_Amount_Space_Combat_Won                           := 2
  set lng_AI_Anger_Amount_Space_Combat_Lost                          := 4
  set lng_AI_Anger_Amount_Space_Combat_Stalemate                     := 3
  set lng_AI_Anger_Amount_Ground_Combat_Won                          := 3
  set lng_AI_Anger_Amount_Ground_Combat_Lost                         := 5
  set lng_AI_Anger_Amount_Ground_Combat_Stalemate                    := 4
  set lng_AI_Anger_Amount_Mine_Explosion                             := 2

  // Treaty benefits
  set lng_AI_Anger_Amount_Treaty_Designs_Received                    := -2
  set lng_AI_Anger_Amount_Treaty_Maps_Received                       := -2
  set lng_AI_Anger_Amount_Treaty_Tech_Provided                       := -4
  set lng_AI_Anger_Amount_Treaty_Comm_Channels_Provided              := -2
  set lng_AI_Anger_Amount_Treaty_Espionage_Info_Provided             := -2
  set lng_AI_Anger_Amount_Treaty_Combat_Info_Provided                := -2

  // Intel events
  set lng_AI_Anger_Amount_Espionage                                  := 3
  set lng_AI_Anger_Amount_Sabotage                                   := 3
  set lng_AI_Anger_Amount_Planet_Cargo_Bomb                          := 5
  set lng_AI_Anger_Amount_Planet_Conditions_Change                   := 3
  set lng_AI_Anger_Amount_Planet_Plagued                             := 10
  set lng_AI_Anger_Amount_Planet_Population_Change                   := 5
  set lng_AI_Anger_Amount_Planet_Anger_Change                        := 3
  set lng_AI_Anger_Amount_Planet_Riot                                := 5
  set lng_AI_Anger_Amount_Planet_Rebel                               := 10
  set lng_AI_Anger_Amount_Planet_Value_Change                        := 5
  set lng_AI_Anger_Amount_Points_Change                              := 5
  set lng_AI_Anger_Amount_Ship_Damaged                               := 2
  set lng_AI_Anger_Amount_Ship_Cargo_Bomb                            := 2
  set lng_AI_Anger_Amount_Ship_Lost_Supply                           := 2
  set lng_AI_Anger_Amount_Ship_Lost_Movement                         := 2
  set lng_AI_Anger_Amount_Ship_Lost_Experience                       := 2
  set lng_AI_Anger_Amount_Ship_Orders_Changed                        := 2
  set lng_AI_Anger_Amount_Ship_Rebel                                 := 5

  // Stellar Manipulation
  set lng_AI_Anger_Amount_Planet_Destroyed                           := 4
  set lng_AI_Anger_Amount_Star_Destroyed                             := 6
  set lng_AI_Anger_Amount_Blackhole_Created                          := 5
  set lng_AI_Anger_Amount_Nebulae_Created                            := 4
  set lng_AI_Anger_Amount_WP_Closed                                  := 4
  set lng_AI_Anger_Amount_WP_Opened                                  := 0

  // Terran anger amounts for diplomatic messages
  set lng_AI_Anger_Amount_Msg_General                                := -2
  set lng_AI_Anger_Amount_Msg_Reply                                  := -2
  set lng_AI_Anger_Amount_Msg_Declare_War                            := 25
  set lng_AI_Anger_Amount_Msg_Grant_Independence                     := 5
  set lng_AI_Anger_Amount_Msg_Propose_Treaty                         := -5
  set lng_AI_Anger_Amount_Msg_Accept_Treaty                          := -10
  set lng_AI_Anger_Amount_Msg_Accept_Treaty_Changes                  := -5
  set lng_AI_Anger_Amount_Msg_Refuse_Treaty                          := 5
  set lng_AI_Anger_Amount_Msg_Refuse_Treaty_Changes                  := 3
  set lng_AI_Anger_Amount_Msg_Counter_Treaty                         := -2
  set lng_AI_Anger_Amount_Msg_Counter_Treaty_Changes                 := -2
  set lng_AI_Anger_Amount_Msg_Break_Treaty                           := 15
  set lng_AI_Anger_Amount_Msg_Propose_Trade                          := -2
  set lng_AI_Anger_Amount_Msg_Accept_Trade                           := -4
  set lng_AI_Anger_Amount_Msg_Refuse_Trade                           := 4
  set lng_AI_Anger_Amount_Msg_Counter_Trade                          := 0
  set lng_AI_Anger_Amount_Msg_Request_Gift                           := 5
  set lng_AI_Anger_Amount_Msg_Give_Gift                              := -5
  set lng_AI_Anger_Amount_Msg_Accept_Gift                            := -5
  set lng_AI_Anger_Amount_Msg_Refuse_Gift                            := 5
  set lng_AI_Anger_Amount_Msg_Request_Accept                         := -5
  set lng_AI_Anger_Amount_Msg_Request_Refuse                         := 5
  set lng_AI_Anger_Amount_Msg_Request_Surrender                      := 15
  set lng_AI_Anger_Amount_Msg_Propose_Alliance                       := -5
  set lng_AI_Anger_Amount_Msg_Accept_Alliance                        := -10
  set lng_AI_Anger_Amount_Msg_Refuse_Alliance                        := 5
  set lng_AI_Anger_Amount_Msg_Leave_Alliance                         := 15

  // Set Terran anger amounts for ships/units/colonies in their territory
  set lng_AI_Anger_Amount_Ships_In_Territory                         := 2
  set lng_AI_Anger_Amount_Units_In_Territory                         := 5
  set lng_AI_Anger_Amount_Colonies_In_Territory                      := 5

  // Terran anger values
  call AI_Set_Political_Anger_For_Log_Types()
  call AI_Set_Political_Anger_For_Messages()
  call AI_Set_Political_Anger_For_Wars()

  // Terran Treaty & Alliance element anger values
  call AI_Set_Political_Treaty_Elements()
  call AI_Set_Political_Alliance_Elements()

  return TRUE
end

//------------------------------------------------------------------------